package org.ns.longhttp.selector.datamapper;

import com.alibaba.fastjson.JSON;

public class DataResponseEntry {


    private long id;
    private String mtype;
    private Object content;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getMtype() {
        return mtype;
    }

    public void setMtype(String mtype) {
        this.mtype = mtype;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }

    public static DataResponseEntry newInstance(String json) {
        if (json == null || (json = json.trim()).isEmpty()) {
            return null;
        }
        if (json.charAt(0) != '{' || json.charAt(json.length() - 1) != '}') {
            DataResponseEntry responseEntry = new DataResponseEntry();
            responseEntry.setMtype("text");
            responseEntry.setContent(json);
            return responseEntry;
        }
        return JSON.parseObject(json, DataResponseEntry.class);
    }
}
